<template>
    <div class="content_box" @click="toLink(adList[0])">
      <image :src="adList[0].thumbnail" class="img" ref="image" :style="{'height': hei+'px'}" @load="imageLoad"></image>
    </div>
</template>
<script>
	import {
		list
	} from '../../../../api/ad.js'
	export default {
		name: 'adBanner',
		props: ['content'],
		data() {
			return {
				adList: [{}],
				tagIds: [],
				wid:500,
				hei:200,
			}
		},
		created() { // 在实例创建完成后被立即调用
			this.loadAd()
      console.info(this.content)
    },
		methods: {
			imageLoad(event){
				console.info(event)
				if(event.success){
					this.hei = event.size.naturalHeight	* 750 / event.size.naturalWidth
				}
			},
		    toLink(e) {
          console.info(e.path)
          if(e.hasOwnProperty('typeId') && !this.isNull(e.typeId)){
		        if (e.type === 0) {
		        eeui.openPage({
					statusBarType: 'immersion',
					statusBarStyle:false,
		        	url: 'root://pages/goods/product/details.js',
		        	params: e.typeId
		        })
		        } else if (e.type === 9) {
				      	eeui.openPage({
						statusBarType: 'immersion',
						statusBarStyle:false,
						url: 'root://pages/index/wxPage/wxPage.js',
						params: e.typeId
					})
		        }else if(e.path != null){
              eeui.openPage({
                statusBarType: 'immersion',
                statusBarStyle:false,
                url: e.path
              })

            }
		      }
		    },
			loadAd() {
				this.tagIds = this.content.tagids.split(',');
				for (var i = 0; i < this.tagIds.length; i++) {
					this.tagIds[i] = parseInt(this.tagIds[i])
				}
				list({
					tagIds: this.tagIds,
					mchId: this.getGlobalData().mchId,
				}).then(res => {
					this.adList = res.data.data
        })
			}
		},
		components: {},
	}
</script>

<style scoped>
	.content_box {
		/*flex: 1;*/
    margin-top: 20px;
    margin-left: 20px;
    margin-right: 20px;
  }

	.img{
		width: 750px;
	}
</style>
